import axios from 'axios'
import { Loading,Message } from 'element-ui';
const ajax = axios.create({
  // timeout: 5000,
  baseURL:'http://127.0.0.1:3005'
})
var loadingInstance=''
ajax.interceptors.request.use((config) => {
  var a={...config}
  // var a=JSON.parse(b.data)
  console.log(a,a.data.modeltext)
  loadingInstance = Loading.service({
    background:'rgba(0,0,0,0.3)',
    text:a.data.modeltext||'loading...'
  });
  return config
}, (err) => {
  console.log(err)
  loadingInstance.close()
  Message({
    message:'网络错误'
  })
  return err
})
ajax.interceptors.response.use((resp) => {
  loadingInstance.close()
  return resp
},(err)=>{
  console.log(err)
  loadingInstance.close()
  Message({
    message:'网络错误'
  })
  return err
})
export const getTest=()=>{
  return ajax.get('/')
}
export const editArticle=(obj)=>{
  return ajax.post('/editArticle',{
    name:obj.name,
    content:obj.content
  })
}
export const getArticle=(obj)=>{
  return ajax.post('/getArticle',{
    currentPage:obj.currentPage,
    pageSize:obj.pageSize
  })
}
export const getArticleDetail=(obj)=>{
  return ajax.post('/getArticleDetail',{
    id:obj.id
  })
}
export const updateArticleDetail=(obj)=>{
  return ajax.post('/updateArticleDetail',{
    id:obj.id,
    name:obj.name,
    content:obj.content
  })
}
export const delArticle=(obj)=>{
  return ajax.post('/delArticle',{
    id:obj.id,
    currentPage:obj.currentPage,
    pageSize:obj.pageSize,
    modeltext:obj.modeltext
  })
}
export const getUpload=()=>{
  return ajax.post('/getUpload')
}
export const getInit=()=>{
  return ajax.post('/getInit')
}